package com.example.helloworld.persistence;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

public class UserInfo implements Parcelable {
	private String userId;
	private String userName;
	private List<Role> roleSet;
	private boolean adminYn;
	
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public List<Role> getRoleSet() {
		return roleSet;
	}

	public void setRoleSet(List<Role> roleSet) {
		this.roleSet = roleSet;
	}

	public boolean isAdminYn() {
		return adminYn;
	}

	public void setAdminYn(boolean adminYn) {
		this.adminYn = adminYn;
	}

	public UserInfo(Parcel in) {
		this.userId =	in.readString();
		this.userName =	in.readString();
		this.roleSet =	new ArrayList<Role>();
		in.readTypedList(roleSet, Role.CREATOR);
		this.adminYn =	(in.readByte() == (byte)1);
	}

	public UserInfo(final String userId, final String userName, final List<Role> roleSet, final boolean adminYn) {
		this.userId =	userId;
		this.userName =	userName;
		this.roleSet =	roleSet;
		this.adminYn =	adminYn;
	}

	@Override
	public int describeContents() {
		return 0;
	}
	
	@Override
	public void writeToParcel(Parcel arg0, int arg1) {
		arg0.writeString(userId);
		arg0.writeString(userName);
		arg0.writeTypedList(roleSet);
		arg0.writeByte((byte)(adminYn ? 1 : 0));
	}
	
	public static final Parcelable.Creator<UserInfo> CREATOR =
		new Parcelable.Creator<UserInfo>() {

			@Override
			public UserInfo createFromParcel(Parcel source) {
				return new UserInfo(source);
			}

			@Override
			public UserInfo[] newArray(int size) {
				return new UserInfo[size];
			}
		};
			
	public static class Role implements Parcelable {
		private String roleId;
		private String name;
		private int order;

		public String getRoleId() {
			return roleId;
		}

		public void setRoleId(String id) {
			this.roleId = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public int getOrder() {
			return order;
		}

		public void setOrder(int order) {
			this.order = order;
		}

		public Role(Parcel in) {
			this.roleId =	in.readString();
			this.name =		in.readString();
			this.order =	in.readInt();
		}
		
		public Role(final String roleId, final String name, final int order) {
			this.roleId =	roleId;
			this.name =		name;
			this.order =	order;
		}
		
		@Override
		public int describeContents() {
			return 0;
		}

		@Override
		public void writeToParcel(Parcel dest, int flags) {
			dest.writeString(this.roleId);
			dest.writeString(this.name);
			dest.writeInt(this.order);
		}
		
		public static final Parcelable.Creator<UserInfo.Role> CREATOR =
			new Parcelable.Creator<UserInfo.Role>() {

				@Override
				public Role createFromParcel(Parcel source) {
					return new Role(source);
				}

				@Override
				public Role[] newArray(int size) {
					return new Role[size];
				}
			};
	}
}
